package com.bw.ch.baselib;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import kotlin.NotImplementedError;

public abstract class BaseBindingActivity<VDB extends ViewDataBinding> extends AppCompatActivity {

    public VDB mBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getLayout() == 0) {
            throw new NotImplementedError("错误：未实现 getLayout() 方法！");
        }
        mBinding = DataBindingUtil.setContentView(this, getLayout());
        mBinding.setLifecycleOwner(this);
        initView();
        initData();
    }

    public abstract int getLayout();

    protected abstract void initView();

    protected abstract void initData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mBinding != null) {
            mBinding.unbind();
            mBinding = null;
        }
    }
}